package com.jeegit.ecms.front;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jeegit.ecms.domain.CmsArticle;
import com.jeegit.ecms.domain.CmsVideo;
import com.jeegit.ecms.utils.ECMSUtils;

/**
 * 
 * @author 道信
 *
 */
@Controller
@RequestMapping(value = "")
public class FrontController extends BaseController{

    
    /**
     * 主站首页
     */
    @RequestMapping(value = { "" })
    public String defaultIndex(ModelMap model) {
	return "redirect:indexVideo.html";
    }
    
    /**
     * 主站首页
     */
    @RequestMapping(value = { "index" , "index.html" })
    public String index(ModelMap model) {
	initSite("吉林省正崇科技有限责任公司", model);
	return "cmsfront/themes/basic/index";
    }

    /**
     * 视频首页
     */
    @RequestMapping(value = { "indexVideo.html" })
    public String videoIndex(ModelMap model) {
	initSite("热门课程", model);
	model.put("list",ECMSUtils.getIndexVideo());
	return "cmsfront/themes/basic/indexVideo";
    }

    /**
     * 文章首页
     */
    @RequestMapping(value = { "indexArticle.html" })
    public String articleIndex(ModelMap model) {
	initSite("热门文章", model);
	model.put("list",ECMSUtils.getIndexArticle());
	return "cmsfront/themes/basic/indexArticle";
    }

    /**
     * 导航首页
     */
    @RequestMapping(value = { "indexLink.html" })
    public String linkIndex(ModelMap model) {
	initSite("热门导航", model);
	return "cmsfront/themes/basic/indexLink";
    }

    /**
     * 专辑首页
     */
    @RequestMapping(value = { "indexCollection.html" })
    public String collectionIndex(ModelMap model) {
	initSite("热门专辑", model);
	return "cmsfront/themes/basic/indexCollection";
    }

    /**
     * 列表页面
     */
    @RequestMapping(value = { "list.html" })
    public String list(ModelMap model) {
	initSite("社区列表", model);
	return "cmsfront/themes/basic/list";
    }

    /**
     * 视频列表页面
     */
    @RequestMapping(value = { "listVideo.html" })
    public String listVideo(@RequestParam(required=false, defaultValue="1") int pageNum,@RequestParam(required=false, defaultValue="12")  int pageSize, CmsVideo cmsVideo,ModelMap model) {
	initSite("课程列表", model);
	model.put("tableDataInfo",ECMSUtils.getIndexVideoPage(pageNum,pageSize,cmsVideo));
	return "cmsfront/themes/basic/listVideo";
    }

    /**
     * 文章列表页面
     */
    @RequestMapping(value = { "listArticle.html" })
    public String listArticle(@RequestParam(required=false, defaultValue="1") int pageNum,@RequestParam(required=false, defaultValue="12")  int pageSize, CmsArticle cmsArticle,ModelMap model) {
	initSite("文章列表", model);
	model.put("tableDataInfo",ECMSUtils.getIndexArticlePage(pageNum,pageSize,cmsArticle));
	return "cmsfront/themes/basic/listArticle";
    }

    /**
     * 链接列表页面
     */
    @RequestMapping(value = { "listLink.html" })
    public String listLink(ModelMap model) {
	initSite("导航列表", model);
	return "cmsfront/themes/basic/listLink";
    }

    /**
     * 链接列表页面
     */
    @RequestMapping(value = { "listCollection.html" })
    public String listCollection(ModelMap model) {
	initSite("专辑列表", model);
	return "cmsfront/themes/basic/listCollection";
    }

    /**
     * 视频内容页面
     */
    @RequestMapping(value = { "viewVideo-{id}.html" })
    public String viewVideo(@PathVariable long id, ModelMap model) {
	initSite("课程详情", model);
	Boolean isBuy= ECMSUtils.getCmsVideoIsBuy(id);
	model.put("isBuy",isBuy);
	model.put("video", ECMSUtils.getCmsVideo(id,isBuy));
	
	return "cmsfront/themes/basic/viewVideo";
    } 
    
    
    /**
     * 视频内容页面
     */
    @RequestMapping(value = { "viewArticle-{id}.html" })
    public String viewArticle(@PathVariable long id, ModelMap model) {
	initSite("课程详情", model);
	Boolean isBuy= ECMSUtils.getCmsArticleIsBuy(id);
	model.put("isBuy",isBuy);
	model.put("article", ECMSUtils.getCmsArticle(id,isBuy));
	
	return "cmsfront/themes/basic/viewArticle";
    } 

    /**
     * 更新日志
     */
    @RequestMapping(value = { "indexUpdate.html" })
    public String update(ModelMap model) {
	initSite("更新日志", model);
	return "cmsfront/themes/basic/indexUpdate";
    }

    /**
     * 视频计划
     */
    @RequestMapping(value = { "indexPlan.html" })
    public String plan(ModelMap model) {
	initSite("未来计划", model);
	return "cmsfront/themes/basic/indexPlan";
    }
    
    /**
     * 优惠券
     */
    @RequestMapping(value = { "indexCoupon.html" })
    public String listCoupon(ModelMap model) {
	initSite("优惠券", model);
	return "cmsfront/themes/basic/indexCoupon";
    }
    

}
